package org.cs456.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public final class DbOpenHelper extends SQLiteOpenHelper {
	DbOpenHelper(Context context, String db_name, CursorFactory factor, int version) {
		super(context, db_name, null, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// Create Tables
		db.execSQL("CREATE TABLE " + DbConstants.STRING_TABLE
				+ "(id INTEGER PRIMARY KEY AUTOINCREMENT," + " key TEXT,"
				+ " value TEXT);");
		
		db.execSQL("CREATE TABLE " + DbConstants.IMAGE_TABLE
				+ "(id INTEGER PRIMARY KEY AUTOINCREMENT," 
				+ " name TEXT,"
				+ " path TEXT);");
		
		// Populate string data
		db.execSQL("INSERT INTO " + DbConstants.STRING_TABLE
				+ "(key, value) values('name',  'Phil Monroe');");
		db.execSQL("INSERT INTO " + DbConstants.STRING_TABLE
				+ "(key, value) values('oakid', 'pm262106');");

//		// Populate image data
//		db.execSQL("INSERT INTO " + DbConstants.IMAGE_TABLE
//				+ "(name, path) values('OU'," + " 'res/drawable/ou.png'" + ");");
//		db.execSQL("INSERT INTO " + DbConstants.IMAGE_TABLE
//				+ "(name, path) values('icon'," +" 'res/drawable/icon.png'"
//				+ ");");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("drop table if exists "+ DbConstants.IMAGE_TABLE);
		db.execSQL("drop table if exists "+ DbConstants.STRING_TABLE);
		onCreate(db);
	}
	
//	@Override
//	public void onOpen(SQLiteDatabase db) {
//		super.onOpen(db);
//		db.execSQL("delete from "+ DbConstants.IMAGE_TABLE);
//	}

}